<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Document</title>
</head>
<style>
  .router-link-active{
    background-color: blue;
    color: #fff;
  }
  .news .router-link-exact-active{
    background-color: chartreuse;
    color: red;
  }
</style>
<body>
<div id="app">
  <router-link tag="button" :to="{
    path: '/home',
    query: {
      a:10
    }
  }">首页</router-link>
  <router-link tag="button" :to="{
    path: 'news',
    query: {
      a:10,
      b:20
    }
  }">新闻</router-link>
  <router-link tag="button" to="/about">关于</router-link>
  <hr>
  <router-view></router-view>
</div>
</body>
<script src="https://cdn.bootcdn.net/ajax/libs/vue/2.6.12/vue.js"></script>
<script src="https://cdn.bootcdn.net/ajax/libs/vue-router/3.5.1/vue-router.js"></script>
<script>

const NewsGnei = {
  template:`
    <div>
      <h2>我是国内新闻</h2>
    </div>
  `
}
const NewsGwai = {
  template:`
    <div>
      <h2>我是国外新闻</h2>
    </div>
  `
}
const Home = {
  template:`
    <div>
      <h2>我是首页</h2>
    </div>
  `,
  mounted(){
    console.log( this.$route );
  }
}
const News = {
  template:`
    <div class="news">
      <h2>我是新闻页</h2>
      <hr/>
      <router-link tag="button" to="/news/newsnei">国内新闻</router-link>
      <router-link tag="button" to="/news/newswai">国外新闻</router-link>
      <hr/>
      <router-view></router-view>
    </div>
  `,
  mounted(){
    console.log( this.$route );
    console.log( this.$route.query );
  }
}
const About = {
  template:`
    <div>
      <h2>我是关于我们</h2>
    </div>
  `,
  mounted(){
    console.log( this.$route );
  }
}
const routes = [
  {
    path: '/home',
    name: 'home',
    component: Home
  },
  {
    path: '/news',
    name: 'news',
    component: News,
    children:[
      {
        path: '/news/newsnei',
        component: NewsGnei
      },
      {
        path: '/news/newswai',
        component: NewsGwai
      },
    ]
  },
  {
    path: '/about',
    name: 'about',
    component: About
  },
]
const router = new VueRouter({
  routes
})
const vm = new Vue ( {
  el: '#app',
  router
} )
</script>
</html>